pro plotlidartemp, files, output_filename= output_filename, title=title, range = range, max_line_num=max_line_num, energy=energy

	; dealing with args
    if(n_elements(files) eq 0) then files = dialog_pickfile(filter='*.txt',/multiple_files);
    if(n_elements(output_filename) eq 0) then output_filename = 'idl.ps'
	if(n_elements(title) eq 0) then title = ''
	if(n_elements(max_line_num) eq 0) then max_line_num = 10000L
	; read the data
    data = readlidartxt(files, max_line_num=max_line_num);

	; get ps ready
    ps_start, filename=output_filename,/inches, xsize=10, ysize=6
    colornames=load_coyote_colors()
    
    position = [0.07,0.15, 0.93, 0.9]
    
	; get time labels ready
    dummy = label_date(date_format=['%H:%I','%M %D, %Y'] )
    start_j = min(data.julian)
	end_j = max(data.julian)
	hours = (end_j - start_j) / $
		( julday(1, 1, 2000, 1, 0, 0) - julday(1, 1, 2000, 0, 0, 0) )
	; automaticly decide time label interval
	x_interval = 6
	if(hours ge 72) then x_interval = 12
	if(hours ge 144) then x_interval = 24
	if(hours le 6) then x_interval = 1
	if(hours le 3) then x_interval = 0.5
	if(hours le 1) then x_interval = 10
	if(hours le 0.2) then x_interval = 1

 
	if(n_elements(range) eq 0) then begin
		all_temp = [data.temp_detector, data.temp_laser, data.temp_box];
		range = [min(all_temp[where(all_temp gt 0.0)]) , max(all_temp[where(all_temp gt 0.0)]) + 1.0] ;// max + 1.0 to leave some space for the legends.
	endif
	print, "plotting temperature range:" , range

    plot, /nodata, data.julian, indgen(n_elements(data.julian)), $
		yrange = range , $
		position=position, xstyle=1, ystyle=8, $
		charsize = 1.0 , title = title, ytitle = 'degrees celsius', $
		XTICKFORMAT=['LABEL_DATE', 'LABEL_DATE'], xtickunits=['Time','Day'], $
		xtickinterval = x_interval, xticklen=-0.02, yticklen = -0.01, $ 
		color = colornames.black, /noerase
    oplot, data.julian, data.temp_box, color=colornames.red
	oplot, data.julian, data.temp_detector, color=colornames.blue
	oplot, data.julian, data.temp_laser, color=colornames.dark_green
	
	legend, ['laser', 'detector' , 'box'], psym=[0,0,0], colors=[colornames.dark_green, colornames.blue, colornames.red], position=[0.08, 0.88], /norm, textcolors=colornames.black

	if(keyword_set(energy)) then begin
		energy_range=[min(data.energy[where(data.energy gt 0.0)]), max(data.energy[where(data.energy gt 0.0)]) + 0.5];
		axis, yaxis=1, yrange=energy_range, ytitle='energy', /noerase, color=colornames.black, /save, /nodata, charsize=1.0, yticklen=-0.01
		oplot, data.julian, data.energy, color=colornames.gray
		legend, 'energy', psym=0, colors=colornames.gray, position=[0.70, 0.88], /norm, textcolors=colornames.black
		

	endif
    
    ps_end, /png, /allow_transparent
    
    
end
